home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / iwf12.zip / MODULES / SAMP_WIN.C < prev    next >
C/C++ Source or Header  |  1994-01-21  |  7KB  |  208 lines

  1. /*
  2. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. MODULE: SAMP_WIN.C (SAMP_WIN Image viewer)
  4.  
  5. AUTHOR: Craig Muller P. Eng. 1991,1992,1993
  6.         cmuller@ccu.umanitoba.ca
  7.         Computer Vision Laboratory
  8.         Mech. Engn.,Univ. of Manitoba
  9.         Winnipeg, Manitoba. CANADA. R3T 2N2
  10.  
  11.  
  12. DESCRIPTION:
  13. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. */
  15. #include <windows.h>
  16.  
  17. #pragma hdrstop
  18.  
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <stdlib.h>
  22.  
  23. #include "iwf.h"
  24.  
  25. // Defines.
  26. #define  MODULENAME "SAMPWIN"
  27. #define  CLASSNAME  MODULENAME"User"
  28.  
  29. // Exported Procedures.
  30. long far PASCAL _export WP_SampWin(HWND hWnd,WORD wMsg,WORD wParam,LONG lParam);
  31.  
  32. // Public variables
  33. HWND hWndSampWin;
  34.  
  35. // Private variables
  36. static HINSTANCE hInst;              // Application instance handle.
  37.  
  38. /*
  39. --------------------------------------------------------------------------
  40. SampWin()
  41. ~~~~~~~~
  42.  
  43. SAMP_WIN STARTUP PROCESSING PROCEDURE.
  44. This is called when the user selects this option from the main menu.
  45. This procedure check to see if the popup window exists. If so it simply
  46. passes focus to the window and returns since there is nothing more to do.
  47. If it does not exist then it proceeds to create the popup window and menu
  48. and displays it on the screen. The popup window acts like a sub-program
  49. within the main program and receives messages from the main program.
  50. --------------------------------------------------------------------------
  51. */
  52. void SampWin(HWND hWndParent)
  53.    {
  54.    char   msg[80];
  55.    WNDCLASS  wc;
  56.    HANDLE  hInst;
  57.  
  58.    // If an instance exists then set focus to that instance and return.
  59.    if (IsWindow(hWndSampWin))
  60.       {
  61.       SetFocus(hWndSampWin);
  62.       return;
  63.       }
  64.  
  65.    hInst = GetWindowWord(hWndParent,GWW_HINSTANCE);
  66.  
  67.    // Register a new window class for the popup window.
  68.    if (!GetClassInfo(hInst,CLASSNAME,&wc))
  69.       {
  70.       memset(&wc,0,sizeof(WNDCLASS));            // Zero init structure.
  71.  
  72.       wc.lpszClassName = CLASSNAME;              // Name for CreateWindow.
  73.       wc.style         = CS_SAVEBITS;            // Extra style parameters.
  74.       wc.lpfnWndProc   = (WNDPROC)WP_SampWin;     // Func to get msgs
  75.       wc.hInstance     = hInst;                  // App that owns the class
  76.       wc.hCursor       = LoadCursor(hInst,"CROSSHAIR");
  77.       wc.lpszMenuName  = MODULENAME;
  78.       wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  79.  
  80.       if (!RegisterClass(&wc))                   // Initialize new window class.
  81.          {
  82.          char sz[80];
  83.  
  84.          sprintf(sz,"RegisterClass() failure! -> %s",CLASSNAME);
  85.          MessageBeep(MB_ICONEXCLAMATION);
  86.          MessageBox(NULL,sz,NULL,MB_OK | MB_ICONEXCLAMATION);
  87.          return;                                 // Exit on failure
  88.          }
  89.       }
  90.  
  91.    // Window class is registered, now create an window from the class.
  92.    hWndSampWin = CreateWindow(CLASSNAME,MODULENAME,
  93.                              WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX | WS_VISIBLE,
  94.                             500,100,400,200,hWndParent,NULL,hInst,NULL);
  95.    if (!hWndSampWin)
  96.       {
  97.       sprintf(msg,"CreateWindow() failure! -> %s",CLASSNAME);
  98.       MessageBeep(MB_ICONEXCLAMATION);
  99.         MessageBox(NULL,msg,NULL,MB_OK | MB_ICONEXCLAMATION);
  100.       return;
  101.       }
  102.  
  103.    SetFocus(hWndSampWin);
  104.    }
  105.  
  106.  
  107.  
  108. /*
  109. ===============================================================================
  110. long far PASCAL _export WP_SampWin(HWND hWnd,WORD wMsg,WORD wParam,LONG lParam)
  111.  
  112. Decription:
  113. This window procedure handles all the messaging for the SampWin Image Viewing
  114. module. Special code is called which produces a red and blue composite
  115. image from both left and right grey scale image. The user the puts on red
  116. and blue 3D glasses to view the image in 3D.
  117. ===============================================================================
  118. */
  119. long far PASCAL _export WP_SampWin(HWND hWnd,WORD wMsg,WORD wParam,LONG lParam)
  120.    {
  121.    switch (wMsg)
  122.       {
  123.       case WM_CREATE:                            // WINDOW CREATION.
  124.       break;
  125.  
  126.       case WM_PAINT:                             // IMAGE NEEDS PAINTING.
  127.       {
  128.       RECT rc;
  129.       PAINTSTRUCT ps;
  130.       HICON hIcon;
  131.  
  132.       BeginPaint(hWnd,&ps);
  133.       if (IsIconic(hWnd))
  134.          {
  135.          hIcon = LoadIcon(hInst,MODULENAME);
  136.          DrawIcon(ps.hdc,2,3,hIcon);
  137.          DestroyIcon(hIcon);
  138.          }
  139.       else
  140.          {
  141.             GetClientRect(hWnd,&rc);
  142.             FillRect(ps.hdc,&rc,GetStockObject(LTGRAY_BRUSH));
  143.             }
  144.       EndPaint(hWnd,&ps);                        // Painting complete.
  145.       }
  146.       break;
  147.       
  148.       case WM_LBUTTONUP:                         // LEFT BUTTON UP.
  149.       case WM_RBUTTONUP:                         // RIGHT BUTTON UP.
  150.         {
  151.         HDC hDC;
  152.         char sz[80];
  153.         int scale;
  154.         RECT rc;
  155.         IMAGE *image;
  156.  
  157.         hDC = GetDC(hWnd);
  158.         GetClientRect(hWnd,&rc);
  159.         rc.bottom = 100;
  160.         FillRect(hDC,&rc,GetStockObject(LTGRAY_BRUSH));
  161.         SetBkColor(hDC,GetSysColor(COLOR_BTNFACE));
  162.         if (IsWindow((HWND)wParam))
  163.             {
  164.             image = GetImage((HWND)wParam);
  165.             scale = GetScale((HWND)wParam);
  166.             sprintf(sz,"Message from image window");
  167.             TextOut(hDC,10,10,sz,strlen(sz));
  168.             sprintf(sz,"File: %s",image->fspec);
  169.             TextOut(hDC,10,25,sz,strlen(sz));
  170.             sprintf(sz,"Scale: %d  Width: %d  Height: %d",scale,image->hres,image->vres);
  171.             TextOut(hDC,10,40,sz,strlen(sz));
  172.             }
  173.         else
  174.             {
  175.             sprintf(sz,"Message from user window");
  176.             TextOut(hDC,10,10,sz,strlen(sz));
  177.             hWndMod = hWnd;                        // Make this module active.
  178.             }
  179.         ReleaseDC(hWnd,hDC);
  180.         }
  181.         break;
  182.  
  183.         case WM_CHAR:
  184.         case WM_COMMAND:                           // MENU COMMAND SELECTED.
  185.         break;
  186.  
  187.         case WM_SETFOCUS:                          // FOCUS HAS BEEN SET.
  188.       if (FlashWindow(hWnd,TRUE))
  189.          FlashWindow(hWnd,TRUE);                 // Make this module active.
  190.       hWndMod = hWnd;                            // Make this module active.
  191.       BringWindowToTop(hWnd);                    // Bring this module to top.
  192.       InvalidateRect(hWnd,NULL,FALSE);           // Invalidate this image.
  193.       UpdateWindow(hWnd);                        // Update this image.
  194.       break;
  195.  
  196.       case WM_DESTROY:                           // DESTROY WINDOW.
  197.       break;
  198.  
  199.       default:                                   // Pass on if unprocessed.
  200.       return(DefWindowProc(hWnd, wMsg, wParam, lParam));
  201.       }
  202.  
  203.    lParam=lParam;
  204.  
  205.    return(NULL);
  206.    }
  207.  
  208.